Repository navigation
(Closes #3367) statement next_accesses - #3560
LonelyCat124 wants to merge 32 commits into
Conversation
|
I've not implemented the tests for this yet - I'm not sure if there should be any specific order to the result (or whether that should matter). I'm wondering if it should be sorted by abs_position or not. I do think that for some blocks the way this has to be implemented at current will be prohibitively expensive, but the only solution to that will be a rewrite of the DUCs. However, for the LFRic halo exchange infrastructure that requires this code I'm hopeful its not too expensive. |
|
Looking at #3399, the way I implemented this for Assignments was to return a dictionary of In this PR I thought that distinguishing between them is not so relevant, the caller should be worrying about the result, and next/previous_accesses should always return just @arporter @sergisiso Do you agree? If so I'll modify |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3560 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 403 403
Lines 57394 57604 +210
==========================================
+ Hits 57394 57604 +210 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
It would be good to have a reminder/plan about how we are going to use this to do the HEx with the DUC. Does completing #3124 changes the need for these? For instance in the loop implementation you have Are this methods equivalent to: |
I don't remember to be honest, I think we need Kern to be a I could just do
Not quite, it should be similar, but with node equality rules that wouldn't quite work I think. It also doesn't return any accesses contained inside the Swapping Assignment to just return a singular list was easy and didn't cause any side effects anywhere that I can see (as it was done in preperation for this PR I believe) so I've made that change and will continue to implement tests, as I think they'll make it clearer. |
I'm a bit lost by this, could you show an example of an statement where it would have different results? |
If you just do |
… into 3367_statement_next_access
My worry is that next_accesses would return the ReadAfterRead without a way to differenciate them? In the Reference.next_accesses it is not a problem because we can do the is_read/is_write of both the location and target. But in a next_accesses of the statement we cannot do that.
Then maybe something like: |
I guess I don't remember if we have some way to check if a Statement has read/write access to a variable with reference_accesses anyway? I think thats sufficient to distinguish between WaR and RaR.
Because nodes aren't hashable this doesn't work, we can't put them in sets. |
|
Also calling ref.next_accesses() repeatedly is currently inefficient (until the DUC rewrite) as assignment.next_accesses() is more efficient where possible, and I can probably do a similar trick for some of loop's nodes later. |
|
Been a bit slow with this sorry, a first implementation is ready for a first look @sergisiso @arporter . I do (at some point during the review process) want to look at potentially improving the performance of the loop implementation, and maybe look at some of the DSL nodes implementations (may need some advice there), but a first review to see how it works would be better first I think. |
|
@sergisiso Not everything is fixed (far from it) but can you look at the new implementations of Statement and Loop and let me know if you're ahppy with these changes? If so, I'll continue with those changes. |
|
@sergisiso I think this is ready for a first proper look now. |
sergisiso
left a comment
There was a problem hiding this comment.
Sorry for the slow progress on reviewing this @LonelyCat124 , I'm fine with the finer details of the implementation but my main problem is that I don't know what to decide about:
-
Having two different behaviours of these methods, some find their children's references (with their own logic for performance reasons) and some don't (they simply return [] even when they have children). If it were up to me I would prefer a single behaviour. But without use cases its difficult to say what will be useful in practice.
-
I don't particularly like that these are abstract methods but many of their implementations are just
return super().previous_accesses(). I think I would make them not abstract, and delete all the empty implementations. But again this makes more sense with a single behaviour. I think you decided to use an abstract method to force each node to choose which behaviour they have? But this adds lots of verbosity.
Maybe it would be good to have a third opinion from @arporter about these points. I'm happy to compromise if needed so that this PR doesn't remain paused any longer.
Some of the domain-specific nodes I wasn't sure whether it made sense to look at their children or not, so my initial implementation was left as I went for an abstractmethod as a defensive programming measure mostly - it prevents the creation of Statement subclasses without this method being implemented and forces a specific decision to be made about their behaviour, even if that behaviour is just to use the parent class' implementation. |
| :returns: the combined next_accesses for the children of this | ||
| WhileLoop | ||
| ''' | ||
| next_accesses = self._get_next_accesses(self.loop_body[:]) |
There was a problem hiding this comment.
From my reading of the discussion, this can't be as simple as self.children[:] because we'd end up with accesses within the loop body?
That said, what's the reason that Loop and WhileLoop have distinct implementations?
There was a problem hiding this comment.
Performance and node structure - I combine the DUC calls where I can (as they're expensive), but these need to be for self.condition.walk(Reference) vs variable/start/stop/step.walk(Reference). Also note that using _get_next_accesses is essentially a recursive call to next_accesses on all the nodes (which will all be Statements and thus will combine calls to the DUC wherever possible by implementation), whilst the "condition" (for lack of a combining term) is done directly to the DUC for the combined set of all references.
I guess in principle you could implement a shared method for both, however WhileLoop and Loop share no ancestor other than Statement its not really feasible.
There was a problem hiding this comment.
Ah. I hadn't appreciated that WhileLoop is not a Loop. That doesn't seem to be ideal. I also hadn't grasped the distinction between condition and the start/stop/step properties.
|
|
||
| :returns: an empty list. | ||
| ''' | ||
| return [] |
There was a problem hiding this comment.
In the existing PSy-layer DA, these lists comprise Kern and HaloExchange nodes (I think, perhaps PSyLoop as well?).
There was a problem hiding this comment.
Perhaps these methods should just raise NotImplementedError for now and we can think about them in a next step?
There was a problem hiding this comment.
It is the PSyLoop objects that hold information on the depth of halo access and are (currently) responsible for creating HaloExchange objects in the Schedule. I can't remember why it was implemented in that way. Thinking about it now, it feels like something that should be done as a final step in the creation of the initial Schedule of the PSy layer.
There was a problem hiding this comment.
Added - I didn't bother with a message on these classes - I can add one if you feel its necessary.
I can see both arguments (defensive programming versus verbosity) but am inclined to agree with Sergi here - i.e. remove the abstract property and remove the empty implementations. We don't add new Node types very often after all. |
|
Regarding the "returns different things", I'm more relaxed. However, the DSL-level nodes should probably raise a NotImplementedError rather than silently do the wrong thing. I appreciate that this might get triggered unexpectedly though so it's a suck-it-and-see. |
|
@sergisiso @arporter I think this is ready for another look now. |
No description provided.